package com.chen.webservice.Utils;


import com.chen.webservice.model.Order;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Set;

public class RuleConstants {
    public static final int LINKED_AND_TRACING = 1;
    public static final int LINKED = 2;
    public static final int NOT_LINKED = 3;
    public static final Set<Long> ORIGINAL_NORMAL_DESC = Sets.newHashSet(1L, 2L, 3L);
    public static final String EMPTY_COLLECT_DESC = "开发者已声明暂未收集任何用户隐私数据。";
    public static final String EMPTY_SHARE_DESC = "开发者已声明暂未向其他第三方公司或组织共享收集到您的数据。";
    private static final Random random = new Random();

    public static void zhidinMut(List<Order> orders, int i) {
//        int index1 = random.nextInt(orders.size());
        int index2 = random.nextInt(orders.size());
        Order order1 = orders.get(i);
        Order order2 = orders.get(index2);
        if(order1.getId() == order2.getId()){
            return;
        }
        orders.remove(i);
        orders.add(i, order2);
        orders.remove(index2);
        orders.add(index2, order1);
    }


    //节目类型
    public enum OrderType {
        BUSINESS(1, "商业"),
        GOVERNMENT(2, "政府"),
        OTHER(3, "城市之窗"),
        ORIGIN(4, "自制"),
        FIXED(5, "整点/半点广告");
        private int value;
        private String key;

        OrderType(int value, String key) {
            this.value = value;
            this.key = key;
        }

        public int getValue() {
            return this.value;
        }

        public String getKey() {
            return this.key;
        }

        public static OrderType findByType(int value) {
            for (OrderType orderType : OrderType.values()) {
                if (orderType.getValue() == value) {
                    return orderType;
                }
            }
            return ORIGIN;
        }

        public static OrderType getRand() {
            int limit = OrderType.values().length;
            return OrderType.values()[RuleConstants.randInt(limit)];
        }
    }

    //播放类型
    public enum PlayType {
        COVER(1, "包屏"),
        LOOP(0, "轮播");
        private int value;
        private String key;

        PlayType(int value, String key) {
            this.value = value;
            this.key = key;
        }

        public int getValue() {
            return this.value;
        }

        public String getKey() {
            return this.key;
        }

        public static PlayType findByType(int value) {
            for (PlayType playType : PlayType.values()) {
                if (playType.getValue() == value) {
                    return playType;
                }
            }
            return LOOP;
        }

    }

    //节目品类
    public enum CateType {
        WINE(1, "酒类"),
        CAR(2, "汽车"),
        CLOTHES(3, "服装"),
        BANK(4, "银行"),
        ELECT_EQUIPMENT(5, "电器"),
        DAIRY_PRODUCT(6, "乳制品"),
        TRIP(7, "旅游"),
        GYM(8, "体育"),
        PROGRAMME(9, "节目"),
        CONFERENCE(10, "会议活动"),
        JUDICATURE(11, "司法"),
        PUBLIC_WELFARE(12, "公益宣传"),
        LUXURY(13, "奢侈品"),
        MOVIE(14, "电影"),
        GLASS(15, "镜片"),
        SHOW(16, "展览"),
        SHIHUA(17, "石化"),
        PERSON(18, "个人"),
        OTHERS(0, "其他");
        private int value;
        private String key;

        CateType(int value, String key) {
            this.value = value;
            this.key = key;
        }

        public int getValue() {
            return this.value;
        }

        public String getKey() {
            return this.key;
        }

        public static CateType findByType(int value) {
            for (CateType cateType : CateType.values()) {
                if (cateType.getValue() == value) {
                    return cateType;
                }
            }
            return OTHERS;
        }

        public static CateType getRand() {
            int limit = CateType.values().length;
            return CateType.values()[RuleConstants.randInt(limit)];
        }
    }

    //节目风格
    public enum StyleType {
        WORD(1, "文字"),
        COMIC(2, "动画"),
        COLOR(3, "色块"),
        SPECIAL_EFFICACY(4, "特效"),
        OTHERS(0, "其他");
        private int value;
        private String key;

        StyleType(int value, String key) {
            this.value = value;
            this.key = key;
        }

        public int getValue() {
            return this.value;
        }

        public String getKey() {
            return this.key;
        }

        public static StyleType findByType(int value) {
            for (StyleType styleType : StyleType.values()) {
                if (styleType.getValue() == value) {
                    return styleType;
                }
            }
            return OTHERS;
        }

        public static StyleType getRand() {
            int limit = StyleType.values().length;
            return StyleType.values()[RuleConstants.randInt(limit)];
        }
    }

    //节目色系
    public enum ColorType {
        RED(1, "红色"),
        ORANGE(2, "橙色"),
        YELLOW(3, "黄色"),
        GREEN(4, "绿色"),
        CYAN(5, "青色"),
        BLUE(6, "蓝色"),
        PURPLE(7, "紫色"),
        BLACK(8, "黑色"),
        WHITE(9, "白色"),
        PINK(10, "粉色"),
        OTHERS(0, "其他");
        private int value;
        private String key;

        ColorType(int value, String key) {
            this.value = value;
            this.key = key;
        }

        public int getValue() {
            return this.value;
        }

        public String getKey() {
            return this.key;
        }

        public static ColorType findByType(int value) {
            for (ColorType colorType : ColorType.values()) {
                if (colorType.getValue() == value) {
                    return colorType;
                }
            }
            return OTHERS;
        }

        public static ColorType getRand() {
            int limit = ColorType.values().length;
            return ColorType.values()[RuleConstants.randInt(limit)];
        }
    }

    //节目评分
    public enum OrderRate {
        RATE_0(0, "0分"),
        RATE_1(1, "1分"),
        RATE_2(2, "2分"),
        RATE_3(3, "3分"),
        RATE_4(4, "4分"),
        RATE_5(5, "5分"),
        RATE_6(6, "6分"),
        RATE_7(7, "7分"),
        RATE_8(8, "8分"),
        RATE_9(9, "9分"),
        RATE_10(10, "10分");
        private int value;
        private String key;

        OrderRate(int value, String key) {
            this.value = value;
            this.key = key;
        }

        public int getValue() {
            return this.value;
        }

        public String getKey() {
            return this.key;
        }

        public static OrderRate findByType(int value) {
            for (OrderRate orderRate : OrderRate.values()) {
                if (orderRate.getValue() == value) {
                    return orderRate;
                }
            }
            return RATE_0;
        }

        public static OrderRate getRand() {
            int limit = OrderRate.values().length;
            return OrderRate.values()[RuleConstants.randInt(limit)];
        }
    }

    //节目时效
    public enum OrderAging {
        LONG_TERM(1, "长期"),
        YEAR(2, "年度"),
        QUARTER(3, "季度"),
        MONTH(4, "月份"),
        DAY(5, "单日"),
        OTHERS(0, "其他");
        private int value;
        private String key;

        OrderAging(int value, String key) {
            this.value = value;
            this.key = key;
        }

        public int getValue() {
            return this.value;
        }

        public String getKey() {
            return this.key;
        }

        public static OrderAging findByType(int value) {
            for (OrderAging orderAging : OrderAging.values()) {
                if (orderAging.getValue() == value) {
                    return orderAging;
                }
            }
            return OTHERS;
        }

        public static OrderAging getRand() {
            int limit = OrderAging.values().length;
            return OrderAging.values()[RuleConstants.randInt(limit)];
        }
    }

    private static int randInt(int bound) {
        Random random = new Random();
        return random.nextInt(bound);
    }

    public static void printWithCover(List<Order> orders, int startTime, int endTime) {
        List<Order> coverOrders = new ArrayList<>();
        if (CollectionUtils.isEmpty(orders) || orders.size() < 2) {
            return;
        }
        orders.forEach(order -> {
            if (order.getPlayType() == PlayType.COVER.getValue()) {
                coverOrders.add(order);
            }
        });

        if (CollectionUtils.isEmpty(coverOrders)) {
            return;
        }

        for (Order coverOrder : coverOrders) {
            int size = orders.size();
            int played = startTime;
            for (int i = 0; i < size - 1; i++) {
                Order curOrder = orders.get(i);
                Order nxtOrder = orders.get(i+1);
                played+=coverOrder.getPlayTime()*1000;
//                if(played<=)
            }

        }
    }
}

